package com.opt.sample;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

public class NewTask implements Comparable<NewTask> {

	private static Logger LOGGER = Logger.getLogger(NewTask.class);

	public List<NewPackage> candidates = new ArrayList<NewPackage>();

	public List<NewPackage> getCandidates() {
		return candidates;
	}

	public void addCandidate(NewPackage candidate) {
		this.candidates.add(candidate);
	}

	@Override
	public int compareTo(NewTask arg0) {

		LOGGER.debug("WorkOnAlgorithm.goalFunction(this)"
				+ WorkOnAlgorithm.goalFunction(this));
		LOGGER.debug("WorkOnAlgorithm.goalFunction(arg0)"
				+ WorkOnAlgorithm.goalFunction(arg0));

		Double thisGoalFunction = WorkOnAlgorithm.goalFunction(this);
		Double arg0GoalFunction = WorkOnAlgorithm.goalFunction(arg0);

		int equals = 0;
		if (thisGoalFunction != null && arg0GoalFunction != null) {
			equals = thisGoalFunction.compareTo(arg0GoalFunction);
		}
		if (equals > 0) {
			equals = -1;
		} else if (equals < 0) {
			equals = 1;
		}
		return equals;

	}

	public void changeCandidate(int position, NewPackage newCandidate) {

		this.candidates.remove(position);
		this.addCandidate(newCandidate);

	}

}
